/**
 * @author SaoE
 * @date 2025/3/3 19:56
 */
public class _152 {
    public int maxProduct(int[] nums) {
        int len = nums.length;
        int[][] dp = new int[len][2];
        dp[0][0] = nums[0];
        dp[0][1] = nums[0];
        int res = nums[0];
        for (int i = 1; i < len; i++){
            if (nums[i] >= 0){
                dp[i][0] = Math.max(nums[i], dp[i - 1][0] * nums[i]);
//                dp[i][1] = Math.min(nums[i], dp[i - 1][1] * nums[i]);
                dp[i][1] = dp[i - 1][1] * nums[i];
            }else{
//                dp[i][0] = Math.max(nums[i], dp[i - 1][1] * nums[i]);
                dp[i][0] = dp[i - 1][1] * nums[i];
                dp[i][1] = Math.min(nums[i], dp[i - 1][0] * nums[i]);
            }
            res = Math.max(res, dp[i][0]);
        }
        return res;
    }
}
